class Solution {  //查找左区间二分模板 + 查找右区间二分模板  ——》"二段性"
public:
    vector<int> searchRange(vector<int>& nums, int target) {
    int begin = -1, end = -1, n = nums.size(); 
    if(n == 0) return {-1, -1}; //特殊情况，空 ——》防止数组越界

    //1.查区间的左端点
    int left = 0, right = n - 1; 
    while(left < right) //循环条件
    {
        int mid = left + (right - left) / 2; //求中点
        if(nums[mid] < target) left = mid + 1; //< 、>=  ——》"二段性"
        else right = mid;
    }
    if(nums[left] == target) begin = left; //最终结果

    //2.查区间的右端点
    left = 0, right = n - 1;
    while(left < right)  //循环条件
    {
        int mid = left + (right - left + 1) / 2; //求中点
        if(nums[mid] <= target) left = mid;  //<= 、>  ——》"二段性"
        else right = mid - 1;
    }
    if(nums[left] == target) end = right; //最终结果

    return {begin, end};

    }
};